package com.ct.mybatis.mapper;

import com.ct.mybatis.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {
    @Results (id = "BaseMap", value = {
            @Result(column = "delete_flag", property = "deleteFlag"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime")
    })
    @Select("select * from user_info")
    List<UserInfo> selectAll ();

    @ResultMap("BaseMap")
    @Select("select * from user_info where id = #{id}")
    UserInfo selectById (Integer id);

    @Select("select * from user_info where age = #{age} and delete_flag = #{flag}")
    List<UserInfo> selectByAge (Integer age, @Param("flag") Integer daleteFlag);

    @Insert("insert into user_info (username, password, age) values (#{username}, #{password}, #{age})")
    Integer insertUser (UserInfo userInfo);

    @Insert("insert into user_info (username, password, age) values (#{userinfo.username}, #{userinfo.password}, #{userinfo.age})")
    Integer insertUser2 (@Param("userinfo") UserInfo userInfo);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into user_info (username, password, age) values (#{username}, #{password}, #{age})")
    Integer insertUser3 (UserInfo userInfo);

    @Delete("delete from user_info where id = #{id}")
    Integer deleteById(Integer Id);

    @Update("update user_info set password = #{password} where id = #{id}")
    Integer updataById (UserInfo userInfo);

}
